package com.xxl.job.executor.service.access.construction;


import com.web.all.common.bean.response.Result;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.mvc.api.ConstructionApi;
import com.xxl.job.executor.service.duty.PersonnelDutyTaskJobHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@JobHandler(value = "ConstructionJobHandler")
@Component
public class ConstructionJobHandler extends IJobHandler {

    private static final Logger log = LoggerFactory.getLogger(ConstructionJobHandler.class);

    private final ConstructionApi constructionApi;

    public ConstructionJobHandler(ConstructionApi constructionApi) {
        this.constructionApi = constructionApi;
    }

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        XxlJobLogger.log("ConstructionJobHandler, 施工状态同步.");
        try {
            Result result = constructionApi.synchronousStatus();
            if (result.isSuccess()) {
                XxlJobLogger.log("ConstructionJobHandler, 施工状态同步成功.");
                log.info("ConstructionJobHandler, 施工状态同步成功.");
                return SUCCESS;
            }
            XxlJobLogger.log("ConstructionJobHandler, 施工状态同步失败.");
            log.error("ConstructionJobHandler, 施工状态同步失败.原因：{}", result.getMsg());
            return FAIL;
        } catch (Exception e) {
            log.error("ConstructionJobHandler, 施工状态同步失败. 原因：{}", e.getMessage());
            return FAIL;
        }
    }
}
